package com.jxw.launcher.view;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Build;
import android.os.Bundle;
import android.text.Html;
import android.text.Spanned;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import com.jxw.launcher.R;
import com.jxw.launcher.util.DensityUtil;

/* loaded from: classes.dex */
public class CommonDialog extends Dialog {
    protected View barDivider;
    protected View buttonDivider;
    protected FrameLayout container;
    protected View content;
    private final int contentPadding;
    protected DialogInterface.OnClickListener dismissClick;
    protected TextView headerVw;
    public DialogInterface.OnClickListener listener;
    protected Button negativeBt;
    protected Button positiveBt;

    public CommonDialog(Context context) {
        this(context, R.style.dialog_common);
    }

    public CommonDialog(Context context, int i) {
        super(context, i);
        this.dismissClick = new DialogInterface.OnClickListener() { // from class: com.jxw.launcher.view.CommonDialog.1
            @Override // android.content.DialogInterface.OnClickListener
            public void onClick(DialogInterface dialogInterface, int i2) {
                dialogInterface.dismiss();
            }
        };
        this.contentPadding = (int) getContext().getResources().getDimension(R.dimen.global_dialog_padding);
        init(context);
    }

    protected CommonDialog(Context context, boolean z, DialogInterface.OnCancelListener onCancelListener) {
        super(context, z, onCancelListener);
        this.dismissClick = new DialogInterface.OnClickListener() { // from class: com.jxw.launcher.view.CommonDialog.1
            @Override // android.content.DialogInterface.OnClickListener
            public void onClick(DialogInterface dialogInterface, int i2) {
                dialogInterface.dismiss();
            }
        };
        this.contentPadding = (int) getContext().getResources().getDimension(R.dimen.global_dialog_padding);
        init(context);
    }

    protected void init(Context context) {
        setCancelable(false);
        requestWindowFeature(1);
        this.content = LayoutInflater.from(context).inflate(R.layout.common_dialog, (ViewGroup) null);
        this.headerVw = (TextView) this.content.findViewById(R.id.dialog_header);
        this.container = (FrameLayout) this.content.findViewById(R.id.content_container);
        this.barDivider = this.content.findViewById(R.id.button_bar_divider);
        this.buttonDivider = this.content.findViewById(R.id.button_divder);
        this.positiveBt = (Button) this.content.findViewById(R.id.positive_bt);
        this.negativeBt = (Button) this.content.findViewById(R.id.negative_bt);
        int i = Build.VERSION.SDK_INT;
        super.setContentView(this.content);
    }

    @Override // android.app.Dialog
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        if (isTablet(getContext())) {
            int dip2px = DensityUtil.dip2px(getContext(), 360.0f);
            DisplayMetrics displayMetrics = new DisplayMetrics();
            ((WindowManager) getContext().getSystemService("window")).getDefaultDisplay().getMetrics(displayMetrics);
            if (dip2px < displayMetrics.widthPixels) {
                WindowManager.LayoutParams attributes = getWindow().getAttributes();
                attributes.width = dip2px;
                getWindow().setAttributes(attributes);
            }
        }
    }

    @Override // android.app.Dialog
    public void onBackPressed() {
        super.onBackPressed();
        dismiss();
    }

    public void setContent(View view) {
        setContent(view, this.contentPadding);
    }

    public void setContent(View view, int i) {
        this.container.removeAllViews();
        this.container.setPadding(i, i, i, i);
        this.container.addView(view, new FrameLayout.LayoutParams(-1, -1));
    }

    @Override // android.app.Dialog
    public void setContentView(int i) {
        setContent(null);
    }

    @Override // android.app.Dialog
    public void setContentView(View view) {
        setContentView(null, null);
    }

    @Override // android.app.Dialog
    public void setContentView(View view, ViewGroup.LayoutParams layoutParams) {
        throw new Error("Dialog: User setContent (View view) instead!");
    }

    public void setMessage(int i) {
        setMessage(getContext().getResources().getString(i));
    }

    public void setMessage(String str) {
        setMessage(Html.fromHtml(str));
    }

    public void setMessage(Spanned spanned) {
        ScrollView scrollView = new ScrollView(getContext());
        scrollView.setLayoutParams(new FrameLayout.LayoutParams(-1, -2));
        TextView textView = new TextView(getContext(), null, R.style.dialog_pinterest_text);
        textView.setLayoutParams(new FrameLayout.LayoutParams(-1, -2));
        textView.setGravity(1);
        textView.setTextSize(2, 22.0f);
        int i = this.contentPadding;
        textView.setPadding(i, i, i, i);
        textView.setLineSpacing(0.0f, 1.3f);
        textView.setText(spanned);
        textView.setTextColor(getContext().getResources().getColor(R.color.black));
        scrollView.addView(textView, new FrameLayout.LayoutParams(-1, -2));
        setContent(scrollView, 0);
    }

    public void setNegativeButton(int i, DialogInterface.OnClickListener onClickListener) {
        setNegativeButton(getContext().getString(i), onClickListener);
    }

    public void setNegativeButton(String str, final DialogInterface.OnClickListener onClickListener) {
        if (!TextUtils.isEmpty(str)) {
            this.negativeBt.setText(str);
            this.negativeBt.setOnClickListener(new View.OnClickListener() { // from class: com.jxw.launcher.view.CommonDialog.2
                @Override // android.view.View.OnClickListener
                public void onClick(View view) {
                    DialogInterface.OnClickListener onClickListener2 = onClickListener;
                    if (onClickListener2 != null) {
                        onClickListener2.onClick(CommonDialog.this, 0);
                    } else {
                        CommonDialog.this.dismissClick.onClick(CommonDialog.this, 0);
                    }
                }
            });
            this.negativeBt.setVisibility(0);
            if (this.positiveBt.getVisibility() == 0) {
                this.buttonDivider.setVisibility(0);
            }
        } else {
            this.negativeBt.setVisibility(8);
            this.buttonDivider.setVisibility(8);
        }
        if (this.positiveBt.getVisibility() == 0 || this.negativeBt.getVisibility() == 0) {
            this.barDivider.setVisibility(0);
        } else {
            this.barDivider.setVisibility(8);
        }
    }

    public void setPositiveButton(int i, DialogInterface.OnClickListener onClickListener) {
        setPositiveButton(getContext().getString(i), onClickListener);
    }

    public void setPositiveButton(String str, final DialogInterface.OnClickListener onClickListener) {
        if (!TextUtils.isEmpty(str)) {
            this.positiveBt.setText(str);
            this.positiveBt.setOnClickListener(new View.OnClickListener() { // from class: com.jxw.launcher.view.CommonDialog.3
                @Override // android.view.View.OnClickListener
                public void onClick(View view) {
                    DialogInterface.OnClickListener onClickListener2 = onClickListener;
                    if (onClickListener2 != null) {
                        onClickListener2.onClick(CommonDialog.this, 0);
                    } else {
                        CommonDialog.this.dismissClick.onClick(CommonDialog.this, 0);
                    }
                }
            });
            this.positiveBt.setVisibility(0);
            if (this.negativeBt.getVisibility() == 0) {
                this.buttonDivider.setVisibility(0);
            }
        } else {
            this.positiveBt.setVisibility(8);
            this.buttonDivider.setVisibility(8);
        }
        if (this.positiveBt.getVisibility() == 0 || this.negativeBt.getVisibility() == 0) {
            this.barDivider.setVisibility(0);
        } else {
            this.barDivider.setVisibility(8);
        }
    }

    @Override // android.app.Dialog
    public void setTitle(int i) {
        setTitle(getContext().getResources().getString(i));
    }

    @Override // android.app.Dialog
    public void setTitle(CharSequence charSequence) {
        if (charSequence == null) {
            this.headerVw.setVisibility(8);
        }
        this.headerVw.setText(charSequence);
    }

    public static boolean isTablet(Context context) {
        return (context.getResources().getConfiguration().screenLayout & 15) >= 3;
    }
}
